package 设计模式.行为型模式.享元模式;

// 具体享元实现-白色围棋棋子
public class WhiteGoChess extends GoChess{
    // 设置单例模式
    private static volatile WhiteGoChess instance;
    // 设置围棋的颜色
    private WhiteGoChess(String color) {
        super(color);
    }
    public static WhiteGoChess getInstance() {
        if (instance == null) {
            synchronized (WhiteGoChess.class) {
                if (instance == null) {
                    instance = new WhiteGoChess("白色");
                }
            }
        }
        return instance;
    }
}

// 具体享元实现 - 黑色围棋棋子
class BlackGoChess extends GoChess {
    // 设置单例模式
    private static volatile BlackGoChess instance;
    // 设置围棋的颜色
    private BlackGoChess(String color) {
        super(color);
    }
    // 获取享元对象的方法
    public static BlackGoChess getInstance() {
        if (instance == null) {
            synchronized (WhiteGoChess.class) {
                if (instance == null) {
                    instance = new BlackGoChess("黑色");
                }
            }
        }
        return instance;
    }
}
